layui.use(['table', 'jquery','element','layer','form','laydate'], function () {
    var table = layui.table;
    var $ = layui.jquery;
    var element = layui.element;
    var layer = layui.layer;
    var form = layui.form;
    var laydate =layui.laydate;

    laydate.render({
        elem: '#startDate' //指定元素
    });

    laydate.render({
        elem: '#endDate' //指定元素
    });


    //第一个实例
    table.render({
        elem: '#table',
        height: 600,
        toolbar :'#toolbar',
        defaultToolbar : []
        , url: ctx + '/eng/stock/detailPageList?typeId='+$('#typeId').val() //数据接口
        , page: true
        , cols: [[
            {field: 'num', title: '数量', align: 'center',width:'13%',fixed:'left'}
            , {field: 'type', title: '操作类型', align: 'center',width:'10%',fixed:'left',templet:function(d){
                    if(d.type == 1){
                        return "废品回收";
                    }else if(d.type == 2){
                        return "盘点操作";
                    }else{
                        return "废品售出";
                    }
                }}
            , {field: 'price', title: '价格', align: 'center',width:'10%',fixed:'left'}
            , {field: 'sellOut', title: '废品去向', align: 'center',width:'18%'}
            , {field: 'carInfo', title: '车辆信息', align: 'center',width:'18%'}
            , {field: 'remark', title: '备注信息', align: 'center',width:'18%'}
            , {field: 'createTime', title: '操作时间', align: 'center',width:'15%'}
        ]]
    });



    // 条件查询
    $('#submit').click(function(){
        // 重新渲染数据
        table.reload('table', {
            url: ctx + '/eng/stock/detailPageList?typeId='+$('#typeId').val()
            ,where: $('#queryForm').formToObject()
        });
        return false;
    });

    // tool
    table.on('tool(table)', function(obj){
        toolData = obj.data;
        var layEvent = obj.event;

        if(layEvent === 'detail'){
            detail(toolData);
        }


    });

    //toolbar
    table.on('toolbar(table)', function(obj){
        var event = obj.event;
        if(event == 'query'){

        }
    });


    $('#reset').click(function(){
        $('#queryReset').click();
    });

});